package com.qf.security.handler;

import com.qf.core.response.ResponseResult;
import com.qf.core.utils.ServletUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

/**
 * @Author: sin
 * @Date: 2025/5/6 17:13
 * @Description: 权限不足
 **/
@Component
@Slf4j
public class CustomAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException ex) {
        ServletUtils.renderString(response, ResponseResult.fail(HttpStatus.FORBIDDEN.value(), ex.getMessage()));
    }
}
